package com.yourPet.springMVCTest;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.yourPet.springMVCTest.beans.Emp;

public class EmpFormController extends SimpleFormController {
	
	@Override
	protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("deptList", new String[]{"EAD", "EDS"});
		return model;
	}
	
	//你的表单是post方法 才会触发 onSubmit
	@Override
	protected ModelAndView onSubmit(Object command) throws Exception {
		Emp emp = (Emp)command;
		//service.addEmp(emp);
		System.out.println(emp);
		return new ModelAndView("addSuccess");
	}
	
	@Override
	protected void initBinder(HttpServletRequest request,
			ServletRequestDataBinder binder) throws Exception {
		binder.registerCustomEditor(Date.class, 
				new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
	}
}
